<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>登录</title>
	<link href="../css/public.css" rel="stylesheet"/>
	<link href="../css/main.css" rel="stylesheet"/>
	<link href="../css/style.css" rel="stylesheet"/>
	<link href="../css/agent.css?v=1" rel="stylesheet"/>
	<script src="http://www.jq22.com/jquery/jquery-1.9.1.js"></script>
	<script src="../js/swiper.min.js"></script>
	<script src="../js/mobile-util.js"></script>
	<script src="../js/public.js?v=1"></script>
	<script src="../js/jquery.cookie.js"></script>


</head>
<body >

	<img src="../img/loginbg.png" alt="bg" class="loginbgbox">

	<main class="loginbox">
		<div class="logobox">
			<img src="../img/logo.jpg" alt="logo">
		</div>

		<div class="loginsingup-input">
			<div class="lsu">
				<span class="ico ico-username"></span>
				<input type="text" name="username" id="username" value="" placeholder="账号">
			</div>

			<div class="lsu">
				<span class="ico ico-password"></span>
				<input type="password" name="password" unselectable="on"  id="password" value="" placeholder="密码">
			</div>


			<button type="button" class="loginbtn" onclick="getLogin()">登录</button>

		</div>


	</main>


</body>


<script>
	//$.cookie("tooken",null);
	//$.cookie("level",null);
	//var tooken=$.cookie("tooken");
	//var level=$.cookie("level");

	// if(tooken!=""){
	// 	if(level == 1){
    //
	// 		window.location.href="../levelagent/levelagentindex.html?name="+tooken;
	// 		//return false;
    //
    //
	// 	}else if(level == 2){
    //
	// 		window.location.href="agentindex.html?name="+tooken;
	// 		//return false;
	// 	}
	// }

	//console.log(tooken);

	var username=$.cookie("username");
	var psd=$.cookie("psd");


	$('#username').val(username);
	$('#password').val(psd);


	$('#username').mousemove(function () {
		$('#username').focus();
	});

	$('#password').mousemove(function () {
		$('#password').focus();
	});


	function getLogin(){

		var url="http://wifi.qianlh.com";
		//var url="http://192.168.0.132:69";

		var geturl=url+ "/Admin/agentapi/agent_api";

		var username=$('#username').val();

		var psd=$('#password').val();

		if(username==""){
			alert("请输入登录账号");
			$('#username').focus();
			return false;
		}else if(psd==""){
			alert("请输入登录密码");
			$('#username').focus();
			return false;
		}


		$.ajax({
			type: 'get',
			dataType: "json",
			url: geturl + '?agent_qq=' + username+"&password="+psd,
			success: function (data) {
				//console.log(data);

				var suc=data.success;
				var name=data.tooken;

				if(suc.code == 4007){
					alert(suc.message);
					return false;
				}else if(suc.code == 4012){
					alert(suc.message);
					return false;
				}else if(suc.code == 4000){

					//$.cookie('level', ''+ data.level +'',{expires: 3});
					$.cookie('tooken', ''+ name +'',{expires: 3,path:'/'});
					var tooken=$.cookie("tooken");

					$.cookie('username', ''+ username +'',{expires: 3,path:'/'});
					$.cookie('psd', ''+ psd +'',{expires: 3,path:'/'});

					//alert(tooken);
					if(data.level == 1){

						window.location.href="../levelagent/levelagentindex.html";

					}else if(data.level == 2){


						window.location.href="agentindex.html";
					}



				}

			},error:function(data){
				console.log("请检查您的网络");
			}
		});

	}



</script>

</html>
